package com.ruoyi.web.controller.system;

import java.util.List;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ArTableRelation;
import com.ruoyi.system.service.IArTableRelationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 关系信息Controller
 *
 * @author ruoyi_ln
 * @date 2022-03-01
 */
@RestController
@RequestMapping("/system/tablerelation")
public class ArTableRelationController extends BaseController
{
    @Autowired
    private IArTableRelationService arTableRelationService;

    /**
     * 查询关系信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:ar_table_relation:list')")
    @ApiOperation("查询关系信息列表")
    @GetMapping("/list")
    public TableDataInfo list(ArTableRelation arTableRelation)
    {
        startPage();
        List<ArTableRelation> list = arTableRelationService.selectArTableRelationList(arTableRelation);
        return getDataTable(list);
    }

    /**
     * 导出关系信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:ar_table_relation:export')")
    @Log(title = "关系信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ArTableRelation arTableRelation)
    {
       List<ArTableRelation> list = arTableRelationService.selectArTableRelationList(arTableRelation);
       ExcelUtil<ArTableRelation> util = new ExcelUtil<ArTableRelation>(ArTableRelation.class);
       return util.exportExcel(list, "tablerelation");
    }

    /**
     * 获取关系信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:ar_table_relation:query')")
    @ApiOperation("获取关系信息详细信息")
    @ApiImplicitParam(name = "recNo", value = "关系信息编号", required = true, dataType = "String", paramType = "传关系信息编号")
    @GetMapping(value = "/{recNo}")
    public AjaxResult getInfo(@PathVariable("recNo") String recNo)
    {
        return AjaxResult.success(arTableRelationService.selectArTableRelationById(recNo));
    }

    /**
     * 新增关系信息
     */
    @PreAuthorize("@ss.hasPermi('system:ar_table_relation:add')")
    @Log(title = "关系信息", businessType = BusinessType.INSERT)
    @ApiOperation("新增关系信息")
    @ApiImplicitParam(name = "arTableRelation", value = "关系信息对象", required = true, dataType = "ArTableRelation", paramType = "传关系信息对象")
    @PostMapping
    public AjaxResult add(@RequestBody ArTableRelation arTableRelation)
    {
        return arTableRelationService.insertArTableRelation(arTableRelation);
    }

    /**
     * 修改关系信息
     */
    @PreAuthorize("@ss.hasPermi('system:ar_table_relation:edit')")
    @Log(title = "关系信息", businessType = BusinessType.UPDATE)
    @ApiOperation("修改关系信息")
    @ApiImplicitParam(name = "arTableRelation", value = "关系信息对象", required = true, dataType = "ArTableRelation", paramType = "传关系信息对象")
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody ArTableRelation arTableRelation)
    {
        return arTableRelationService.updateArTableRelation(arTableRelation);
    }

    /**
     * 删除关系信息
     */
    @PreAuthorize("@ss.hasPermi('system:ar_table_relation:remove')")
    @Log(title = "关系信息", businessType = BusinessType.DELETE)
    @ApiOperation("删除关系信息")
    @ApiImplicitParam(name = "recNos", value = "关系信息数组", required = true, dataType = "String[]", paramType = "传关系信息数组")
    @GetMapping("/remove/{recNos}")
    public AjaxResult remove(@PathVariable String[] recNos)
    {
        return arTableRelationService.deleteArTableRelationByIds(recNos);
    }
}
